package com.zx.service.impl;

import com.zx.mapper.OrderMapper;
import com.zx.service.OrderService;
import com.zx.vo.OrderVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Service
public class OrderServiceImpl implements OrderService {
    @Autowired
    private OrderMapper orderMapper;

    @Override
    public Map<String, Object> getAllOrder(Integer page, Integer pers) {
        Integer page1=page; //目标页数
        page = (page - 1) * pers;
        List<OrderVo> order = orderMapper.getAllOrder(page, pers); //分页查询所有订单

        Integer count = orderMapper.getCount();//总数量

        Map<String, Object> map = new HashMap<>();

        map.put("total", count);
        map.put("date", order);
        map.put("page", page / pers + 1);
        map.put("pers", pers);

        Integer pageSum = (count / pers) + 1; //总页数
        if (page1 >= pageSum) {
            map.put("hasNext", false);
        }else {
            map.put("hasNext", true);
        }
        return map;
    }

}
